﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Rison.Web.Common;
using Rison.BusinessFacade.Helper;
using Rison.BusinessFacade.Common;
using Rison.BusinessFacade.Entity.ZP;
using Rison.BusinessFacade.Facade.ZP;
using Rison.BusinessFacade.Facade.NRBZ;
using Rison.DataAccess.Common;

namespace Rison.Web.ZP
{
    public partial class SelfExaminationView : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                LoadInfo();
                Databind();
            }
        }

        private void LoadInfo()
        {
            HiddentYear.Value = year;
            HiddenID.Value = departid;

            string zcbstatus = "未填报";
            bool SBStatus = false;
            string NrStatus = "未填报"; 


            SelfExaminationFacade facade = new SelfExaminationFacade();
            YxsbFacade fa =new YxsbFacade();
            NrbzFacade nrfacade = new NrbzFacade();
            
            if (departid != "")
            {
                zcbstatus = facade.isExistSelfExam(departid, Convert.ToInt32(year));
                LabWCL1.Text = facade.getWCL(departid, Convert.ToInt32(year)).ToString();

                SBStatus = fa.isExistSelfExam(departid, year);
               
                NrStatus = nrfacade.isExistSelfExam(departid, year);
                LabWCL2.Text = nrfacade.getWCL(departid, year).ToString();
                
            }

            LabZCBStatus.Text = zcbstatus; 

            LabSBStatus.Text = SBStatus == true ? "填报中" : "未填报";

            LabNrStatus.Text = NrStatus;
        }

        private string departid
        {
            get
            {
                if (!string.IsNullOrEmpty(Request.QueryString["DepartID"]) && CurrentLoginedUser.UserId != "")
                {
                    return Request.QueryString["DepartID"].ToString();
                }
                return "";
            }
        }

        private string year
        {
            get { return string.IsNullOrEmpty(Request.QueryString["year"]) ? System.DateTime.Today.Year.ToString() : Request.QueryString["year"]; }
        }

        #region "Repeater1"
        private void Databind()
        {
            if (departid != "")
            {
                DataSet ds = new HistoryExamFacade().GetInformation(departid, year);

                if (ds !=null && ds.Tables.Count > 0)
                {
                    DataList1.DataSource = ds.Tables[0].DefaultView;
                    DataList1.DataBind();

                    this.PageInfo.InnerHtml = PageNums.GetPageNum(ds, DataList1, 3, departid);
                    ds.Dispose(); ds = null;
                }
            }

            ////get pageddatasource 
            //PagedDataSource pds = new PagedDataSource();
            //pds.AllowPaging = true;
            //pds.DataSource = ds.Tables[0].DefaultView;
            //pds.PageSize = PageSize;
            //pds.CurrentPageIndex = CurrentPage;
            ////this.labCurrentPage.Text = (CurrentPage + 1).ToString();

            ////RecordCount
            //RecordCount = ds.Tables[0].DefaultView.Count;
            ////this.labRowCount.Text = RecordCount.ToString();

            ////PageCount
            //PageCount = pds.PageCount;
            ////this.labPageCount.Text = PageCount.ToString();

            //// dataList Databin
            //Repeater1.DataSource = pds;
            //Repeater1.DataBind();

            ////pre page
            ////if (pds.IsFirstPage)
            ////    this.IPrePage.Enabled = false;
            ////else
            ////    this.IPrePage.Enabled = true;

            //////next page
            ////if (pds.IsLastPage)
            ////    this.INextPage.Enabled = false;
            ////else
            ////    this.INextPage.Enabled = true;

           
            
        }
        #endregion

        #region"分页"
        /// <summary>
        /// 每页显示的条数
        /// </summary>
        private int PageSize
        {
            get
            {
                return 3;
            }
        }
        /// <summary>
        /// 记录数
        /// </summary>
        private int RecordCount
        {
            get { return (ViewState["RecordCount"] == null) ? 0 : Convert.ToInt32(ViewState["RecordCount"]); }
            set { ViewState["RecordCount"] = value; }
        }

        /// <summary>
        /// 多少页
        /// </summary>
        private int PageCount
        {
            get { return (ViewState["pageCount"] == null) ? 0 : Convert.ToInt32(ViewState["pageCount"]); }
            set { ViewState["pageCount"] = value; }
        }

        /// <summary>
        /// 当前第几页
        /// </summary>
        private int CurrentPage
        {
            get { return (ViewState["CurrentPageIndex"] == null) ? 0 : Convert.ToInt32(ViewState["CurrentPageIndex"]); }
            set { ViewState["CurrentPageIndex"] = value; }
        }

        protected void btnPrev_Click(object sender, System.EventArgs e)
        {
            CurrentPage = CurrentPage - 1;
            Databind();
        }

        protected void btnNext_Click(object sender, System.EventArgs e)
        {
            CurrentPage = CurrentPage + 1;
            Databind();
        }

        #endregion


    }
}
